﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsModel
{
    public static class ModelHelper
    {
        public static IList<InventoryLedgerModel> AddInventoryLedgerModel(InwardOutwardModel inwardOutward, string refTypeName)
        {
            List<InventoryLedgerModel> inventoryLedgers = new List<InventoryLedgerModel>();

            for (int i = 0; i < inwardOutward.InwardOutwardDetails.Count; i++)
            {
                InventoryLedgerModel inventoryLedger = new InventoryLedgerModel();

                inventoryLedger.RefID = inwardOutward.RefID;
                inventoryLedger.RefType = inwardOutward.RefType;
                inventoryLedger.RefDate = inwardOutward.RefDate;
                inventoryLedger.PostedDate = inwardOutward.PostedDate;
                inventoryLedger.RefNo = inwardOutward.RefNo;
                inventoryLedger.RefDetailID = inwardOutward.InwardOutwardDetails[i].RefDetailID;
                inventoryLedger.StockID = inwardOutward.InwardOutwardDetails[i].StockID;
                inventoryLedger.InventoryItemID = inwardOutward.InwardOutwardDetails[i].InventoryItemID;
                inventoryLedger.RestaurantMenuID = inwardOutward.InwardOutwardDetails[i].RestaurantMenuID;
                inventoryLedger.Unit = inwardOutward.InwardOutwardDetails[i].UnitID;
                inventoryLedger.UnitPrice = inwardOutward.InwardOutwardDetails[i].UnitPrice;
                if (refTypeName == "PNK")
                {
                    inventoryLedger.InwardQuantity = inwardOutward.InwardOutwardDetails[i].Quantity;
                    inventoryLedger.OutwardQuantity = 0;
                    inventoryLedger.InwardAmount = inwardOutward.InwardOutwardDetails[i].Amount;
                    inventoryLedger.OutwardAmount = 0;
                }
                else
                {
                    inventoryLedger.InwardQuantity = 0;
                    inventoryLedger.OutwardQuantity = inwardOutward.InwardOutwardDetails[i].Quantity;
                    inventoryLedger.InwardAmount = 0;
                    inventoryLedger.OutwardAmount = inwardOutward.InwardOutwardDetails[i].Amount;
                }
                inventoryLedger.JournalMemo = inwardOutward.JournalMemo;
                inventoryLedger.Description = inwardOutward.InwardOutwardDetails[i].Description;
                inventoryLedger.OutwardPurpose = inwardOutward.InwardOutwardDetails[i].OutwardPurpose;
                inventoryLedger.RestaurantID = inwardOutward.RestaurantID;

                inventoryLedgers.Add(inventoryLedger);
            }

            return inventoryLedgers.ToList();
        }

        public static IList<GeneralLedgerModel> AddGeneralLedgerModel(InwardOutwardModel inwardOutward)
        {
            List<GeneralLedgerModel> generalLedgers = new List<GeneralLedgerModel>();

            for (int i = 0; i < inwardOutward.InwardOutwardDetails.Count; i++)
            {
                GeneralLedgerModel generalLedger = new GeneralLedgerModel();

                generalLedger.RefID = inwardOutward.RefID;
                generalLedger.RefDetailID = inwardOutward.InwardOutwardDetails[i].RefDetailID;
                generalLedger.RefType = inwardOutward.RefType;
                generalLedger.RefDate = inwardOutward.RefDate;
                generalLedger.RefNo = inwardOutward.RefNo;
                generalLedger.PostedDate = inwardOutward.PostedDate;
                generalLedger.CurrencyID = inwardOutward.CurrencyID;
                generalLedger.AccountingObjectID = inwardOutward.AccountingObjectID;
                generalLedger.DescriptionMaster = inwardOutward.JournalMemo;
                generalLedger.DescriptionDetail = inwardOutward.InwardOutwardDetails[i].Description;
                generalLedger.Amount = inwardOutward.TotalAmount;
                generalLedger.RestaurantID = inwardOutward.RestaurantID;

                generalLedgers.Add(generalLedger);
            }

            return generalLedgers.ToList();
        }
    }
}
